<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns:ui="http://java.sun.com/jsf/facelets"
                template="/resources/template/template.xhtml"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns="http://www.w3.org/1999/xhtml"
                xmlns:p="http://primefaces.org/ui"
                xmlns:bi="http://java.sun.com/jsf/composite/bill"
                xmlns:pa="http://java.sun.com/jsf/composite/paymentMethod">

    <ui:define name="content">

        <h:panelGroup >
            <h:form  >
                <p:panel rendered="#{!bhtSummeryController.printPreview}" >
                    <f:facet name="header" >
                        <h:panelGrid columns="15"  >
                            <h:outputLabel value="Inward Final Bill" />
                            <h:outputLabel value="&nbsp;&nbsp;&nbsp;&nbsp;" style="min-width: 50px;" />
                            <p:selectOneMenu   id="cmbPs" value="#{bhtSummeryController.current.paymentScheme}">                                                                     
                                <f:selectItems value="#{paymentSchemeController.items}" var="paysch" itemLabel="#{paysch.name}" itemValue="#{paysch}"  />
                                <p:ajax process="cmbPs" update="creditCard cheque slip" event="change" />
                            </p:selectOneMenu>

                            <h:panelGroup id="creditCard" style="display: #{bhtSummeryController.current.paymentMethod ne 'Card' ? 'none' : 'block'} ; ">
                                <pa:creditCard paymentMethodData="#{bhtSummeryController.current.paymentMethodData}"/>
                            </h:panelGroup>

                            <h:panelGroup id="cheque" style="display: #{bhtSummeryController.current.paymentMethod ne 'Cheque' ? 'none' : 'block'} ; " >
                                <pa:cheque paymentMethodData="#{bhtSummeryController.current.paymentMethodData}"/>
                            </h:panelGroup>

                            <h:panelGroup id="slip" style="display: #{bhtSummeryController.current.paymentMethod ne 'Slip' ? 'none' : 'block'} ;">
                                <pa:slip paymentMethodData="#{bhtSummeryController.current.paymentMethodData}"/>
                            </h:panelGroup>

                            <p:commandButton  value="Settle" action="#{bhtSummeryController.settle}" ajax="false"  style="width: 150px; padding: 1px;border: 1px solid ; margin: auto;">
                            </p:commandButton>
                            <p:commandButton value="New Bill" ajax="false" action="#{bhtSummeryController.prepareNewBill()}" >
                            </p:commandButton>
                        </h:panelGrid>
                    </f:facet>       

                    <p:panel header="BHT">                               
                        <p:panelGrid id="panSearch2" columns="2" >
                            <h:outputLabel  value="Name:" />
                            <h:outputLabel  value="#{bhtSummeryController.patientEncounter.patient.person.nameWithTitle}" ></h:outputLabel>
                            <h:outputLabel  value="Sex" />
                            <h:outputLabel  value="#{bhtSummeryController.patientEncounter.patient.age}" ></h:outputLabel>
                            <h:outputLabel value="DOB"  />
                            <h:outputLabel  value="#{bhtSummeryController.patientEncounter.patient.person.dob}"   >
                                <f:convertDateTime pattern="dd/MM/yy" />
                            </h:outputLabel>
                            <h:outputLabel  value="Adress" />
                            <h:outputLabel  value="#{bhtSummeryController.patientEncounter.patient.person.address}" ></h:outputLabel>
                            <h:outputLabel  value="Date of Admission"  />
                            <h:outputLabel  value="#{bhtSummeryController.patientEncounter.dateOfAdmission}"   >
                                <f:convertDateTime pattern="dd/MM/yy" />
                            </h:outputLabel>
                        </p:panelGrid>
                    </p:panel>                    



                    <p:dataTable value="#{bhtSummeryController.chargeItemTotals}" var="c">
                        <p:column >
                            #{c.inwardChargeType}
                        </p:column>
                        <p:column >
                            #{c.total}
                        </p:column>
                        <p:column >
                            <p:inputText autocomplete="off" value="#{c.adjustedTotal}"/>
                        </p:column>
                    </p:dataTable>    

                    <br/><br/>
                    <p:panelGrid columns="2" id="tot" style="min-width: 100%;">
                        <h:outputLabel  value="Total Charges" style="font-weight: bold"/>
                        <h:outputLabel id="gtot" value="#{bhtSummeryController.grantTotal}"/>
                        <h:outputLabel value="Discount" style="font-weight: bold"/>
                        <h:inputText autocomplete="off"  id="dis" value="#{bhtSummeryController.discount}" >
                            <f:ajax event="keyup" execute="gtot dis" render="net due"/>
                        </h:inputText>
                        <h:outputLabel value="Net Charges" style="font-weight: bold"/>
                        <h:outputLabel id="net" value="#{bhtSummeryController.netCharge}"/>
                        <h:outputLabel value="Paid " style="font-weight: bold"/>
                        <h:outputLabel value="#{bhtSummeryController.paid}"/>
                        <h:outputLabel value="Due " style="font-weight: bold"/>
                        <h:outputLabel id="due" value="#{bhtSummeryController.due}"/>
                        <h:outputLabel value="Paying Amount" style="font-weight: bold"/>
                        <h:inputText autocomplete="off"  value="#{bhtSummeryController.current.cashPaid}"/>
                    </p:panelGrid>
                </p:panel>

                <p:panel rendered="#{bhtSummeryController.printPreview}">

                    <bi:inwardBill controller="#{bhtSummeryController}" 
                                   isIntrim="false"
                                   item="#{bhtSummeryController.billItems}"
                                   patientEncounter="#{bhtSummeryController.current.patientEncounter}"
                                   bill="#{bhtSummeryController.current}"/>

                </p:panel>
            </h:form>

        </h:panelGroup>

    </ui:define>

</ui:composition>
